package gw.com.android.ui.bulletin;

import android.os.Bundle;
import android.text.TextUtils;

import gw.com.android.ui.WebFragment;

/**
 * @author jett
 * @since 2018-06-28.
 */
public class BulletinWebFragment extends WebFragment {

    private String mHtml;
    private OverrideUrlListener listener;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mHtml = getArguments().getString("content");
        }
    }

    @Override
    public boolean overrideUrlLoading(String url) {
        return (listener != null && listener.onOverride(url)) || super.overrideUrlLoading(url);
    }

    @Override
    public void loadView() {
        super.loadView();
        if (!TextUtils.isEmpty(mHtml)) {
            mWebView.loadDataWithBaseURL(null, mHtml, "text/html", "utf-8", null);
        }
    }

    public void setOverrideUrlListener(OverrideUrlListener listener) {
        this.listener = listener;
    }

    public interface OverrideUrlListener {
        boolean onOverride(String url);
    }

}